//
//  Pointer.h
//  GLDemo
//
//  Created by wenqi on 5/23/14.
//  Copyright (c) 2014 xiewneqi. All rights reserved.
//

#ifndef __GLDemo__Pointer__
#define __GLDemo__Pointer__

#include <iostream>

template <typename T>
class Pointer
{
public:
    Pointer () : m_buffer (NULL)
    {
        // do nothing
    }
    
    Pointer (Pointer& pointer) : m_buffer (pointer.m_buffer)
    {
        // do nothing
    }
    
    ~Pointer ()
    {
        if (m_buffer != NULL)
        {
            delete m_buffer;
        }
        m_buffer = NULL;
    }
    
public:
    T* Malloc ()
    {
        if (m_buffer != NULL)
        {
            throw "Malloc操作之前请确保缓冲区没有被占用";
        }
        m_buffer = new T ();
        return m_buffer;
    }
    
    void Free ()
    {
        if (m_buffer != NULL)
        {
            delete m_buffer;
            m_buffer = NULL;
        }
    }
    
    T* GetBuffer ()
    {
        return m_buffer;
    }
    
private:
    T *m_buffer;
};


#endif /* defined(__GLDemo__Pointer__) */
